package kaug.loeng3;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

public class ButtonPanel extends JPanel {

	PaintFrame frame;
	// inner
	class ButtonListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			System.out.println(e);
			if (e.getActionCommand().equals("click me")) {
				System.out.println("clicked");
				frame.getDrawPanel().setColor(Color.BLUE);
			} else {
				frame.getDrawPanel().setColor(Color.RED);
				System.out.println("clicked me too");
			}
		}
	}
	
	public ButtonPanel(PaintFrame f) {
		frame = f;
		setBackground(Color.BLUE);
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JButton b = new JButton("click me");
		// class X implements ActionListener {...}
		// b.addActionListener(new X());
		// anonymous class
		b.addActionListener(new ButtonListener());
		add(b);
		
		JButton b2 = new JButton("click me too");
		b2.addActionListener(new ButtonListener());
		add(b2);
	}
}
